package com.tyrant.macaulottery.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.android.architecture.blueprints.todoapp.tasks.TasksActivity;
import com.tyrant.macaulottery.R;
import com.tyrant.macaulottery.banner.StateBean;
import com.tyrant.macaulottery.network.ApiLoader;
import com.tyrant.macaulottery.utils.ResultObserver;

public class SplashActivity extends AppCompatActivity {

    private Intent newIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        newIntent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(newIntent);
        finish();
//        initView();
    }

    private void initView() {
        new ApiLoader().getStateJson().subscribe(new ResultObserver<StateBean>() {
            @Override
            public void onNext(StateBean stateBean) {
                if (stateBean.getState() == 0) {
                    //审核界面
//                    newIntent = new Intent(SplashActivity.this, TasksActivity.class);
                    newIntent = new Intent(SplashActivity.this, TasksActivity.class);
                } else {
                    //真实界面
                    newIntent = new Intent(SplashActivity.this, MainActivity.class);
                }
                startActivity(newIntent);
                finish();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
//                newIntent = new Intent(SplashActivity.this, TasksActivity.class);
                newIntent = new Intent(SplashActivity.this, TasksActivity.class);
                startActivity(newIntent);
                finish();
            }
        });
    }

}
